<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <ex-evaluation-report-form
      ref="realForm"
      @ok="submitCallback"
      :disabled="disableSubmit"
      :bidSectionId="bidSectionId"
    ></ex-evaluation-report-form>
  </j-modal>
</template>

<script>
import ExEvaluationReportForm from './ExEvaluationReportForm'
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'ExEvaluationReportModal',
  components: {
    ExEvaluationReportForm,
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      bidSectionId: '',
      url: {
        queryExEvaluationReport: '/exPingbiao/exEvaluationReport/list',
      },
    }
  },
  methods: {
    add(bidSectionId) {
      this.visible = true
      this.bidSectionId = bidSectionId
      //根据标段id 查询评标报告，如果存在 进行编辑
      this.getInfo(bidSectionId)
    },
    getInfo(bidSectionId) {
      var that = this
      getAction(this.url.queryExEvaluationReport, { bidSectionId: bidSectionId })
        .then((res) => {
          if (res.success && res.result.total > 0) {
            that.$nextTick(() => {
              that.$refs.realForm.edit(res.result.records[0])
            })
          } else {
            this.$nextTick(() => {
              this.$refs.realForm.add()
            })
          }
        })
        .finally(() => {})
    },
    edit(record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.submitForm()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>
